package com.ruoyi.jihuo.api.official;

import com.ruoyi.jihuo.api.ApiStrategy;
import com.ruoyi.jihuo.domain.JhTmAccount;
import com.taobao.top.BaseTopApiRequest;
import com.taobao.top.BaseTopApiResponse;
import com.taobao.top.TopApiClient;
import com.taobao.top.defaultability.Defaultability;
import com.taobao.top.defaultability.request.TmallProductSchemaAddRequest;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.Map;

@Component
public class TmallProductSchemaAddStrategy implements ApiStrategy {
    @Override
    public BaseTopApiResponse execute(TopApiClient client, BaseTopApiRequest request, JhTmAccount jhTmAccount) throws IOException {
        Defaultability apiPackage = new Defaultability(client);
        return apiPackage.tmallProductSchemaAdd((TmallProductSchemaAddRequest) request, jhTmAccount.getJhAppSession());
    }

    @Override
    public BaseTopApiRequest setParams(String api, Map<String, Object> paramMap) {
        TmallProductSchemaAddRequest request = new TmallProductSchemaAddRequest();
        Long categoryId = (Long) paramMap.get("category_id");
        String xmlData = (String) paramMap.get("xml_data");
        request.setCategoryId(categoryId);
        request.setXmlData(xmlData);
        return request;
    }
}
